<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GPRS数据中断统计</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">

function searchAlarmInfo(){
	var startTime=$("#i1").datebox("getValue");
	var endTime=$("#i2").datebox("getValue");
	var startTimeLong = new Date(startTime.replace(new RegExp("-","gm"),"/")).getTime();
	var endTimeLong = new Date(endTime.replace(new RegExp("-","gm"),"/")).getTime();
	
	 if(startTimeLong-endTimeLong>0){
		 $.messager.alert("系统提示","查询开始时间"+startTime+"不能大于结束时间"+endTime+"！");
		 return;
	 }
	 $("#dg").datagrid({url:'${pageContext.request.contextPath}/gprsAlarmInfo/list.do'});
	 $("#dg").datagrid('load',{
		"frontProcessorId":$("#siteName").combobox("geText"),
	 	"startTime":startTimeLong,
	 	"endTime":endTimeLong
	 });
}
	
	function exportAlarmInfoInCurrentPage(){
		var rows = $("#dg").datagrid("getRows");
		 var strIds=[];
		 for(var i=0;i<rows.length;i++){
			 strIds.push(rows[i].alarmInfoId);
		 }
		 var ids=strIds.join(",");
		 window.open('${pageContext.request.contextPath}/alarmInfo/export.do?alarmInfoIds='+ids+'&realtime=0');
	}
	
	function exportByTemplateInCurrentPage(){
		var rows = $("#dg").datagrid("getRows");
		var strIds=[];
		 for(var i=0;i<rows.length;i++){
			 strIds.push(rows[i].alarmInfoId);
		 }
		 var ids=strIds.join(",");
		 window.open('${pageContext.request.contextPath}/alarmInfo/exportByTemplate.do?alarmInfoIds='+ids+'');
	}
	
	function exportAlarmInfoInAllPages(){
		 window.open('${pageContext.request.contextPath}/alarmInfo/export.do?alarmInfoIds='+null+'&realtime=0');
	}
	
	function exportByTemplateInAllPages(){
		 window.open('${pageContext.request.contextPath}/alarmInfo/exportByTemplate.do?alarmInfoIds='+null+'');
	}
	
	function downloadTemplate(){
		window.open('../template/alarmInfoExportTemplate.xls');
	}
	
	function formatDatebox(value) {
		var datetimeType = "";
	    var date =new Date(value);
	    datetimeType = date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()
	    +" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
	    return datetimeType;
	}
	
	function formatJsonObject(value) {
		return JSON.stringify(value);
	}
	
	function formatAlarmType2(value) {
		if(value==1){
			return "服务器CPU使用率告警";
		}else if(value==2){
			return "服务器内存使用率告警";
		}else if(value==3){
			return "服务器硬盘使用率告警";
		}else if(value==4){
			return "前置机故障";
		}else if(value==5){
			return "前置机掉电重启";
		}else if(value==6){
			return "丢包率告警";
		}else if(value==7){
			return "前置机CPU使用率告警";
		}else if(value==8){
			return "前置机内存使用率告警";
		}else if(value==9){
			return "前置机硬盘使用率告警";
		}else if(value==10){
			return "前置机网络连接告警";
		}else if(value==11){
			return "GPRS数据传输异常";
		}else{
			return value;
		}
	}
	
	function formatAlarmClass(val, row, index) {
		var alarmType = row.alarmType;
		if (alarmType == 1 || alarmType == 2 ||alarmType == 3 ||alarmType == 7 ||alarmType == 8 ||alarmType == 9) {
			return "一般告警";
		}
		return "紧急告警";
	}
	
	function formatIsNormal(value) {
		
		if (value == 1) {
			return '自动解除';
		} else if (value == 2) {
			return '手动解除';
		}
		return '';
	}
	
	function formatAlarmDetails(val, row, index) {
		var alarmDetails = row.alarmDetails;
		if(row.alarmType==1){
			return "服务器号:"+alarmDetails.serverId+
					" , CPU使用率:"+alarmDetails.cpuUsageRate+
					"% , CPU使用率告警门限:"+alarmDetails.cpuUsageThreshold+"%";
		}else if(row.alarmType==2){
			return "服务器号:"+alarmDetails.serverId+
					" , 内存使用率:"+alarmDetails.memoryUsageRate+
					"% , 内存使用率告警门限:"+alarmDetails.memoryUsageThreshold+"%";
		}else if(row.alarmType==3){
			return "服务器号:"+alarmDetails.serverId+
					" , 硬盘使用率:"+alarmDetails.harddiskUsageRate+
					"% , 硬盘使用率告警门限:"+alarmDetails.harddiskUsageThreshold+"%";
		}else if(row.alarmType==4){
			return "前置机号:"+alarmDetails.frontProcessorId+
					" , 前置机故障信息:"+alarmDetails.errCode
					/* +
					" , 故障时间:"+formatDatebox(alarmDetails.timestamp*1000) */
					;
		}else if(row.alarmType==5){
			return ""
			/*+"前置机号:"+alarmDetails.frontProcessorId
			 +
					" , 掉电重启时间:"+formatDatebox(alarmDetails.timestamp*1000) */
					;
		}else if(row.alarmType==6){
			return "服务器号:"+alarmDetails.serverId+
					" , 丢包率:"+alarmDetails.packetLossRate+
					"% , 丢包告警门限:"+alarmDetails.packetLossRateThreshold+"%";
		}else if(row.alarmType==7){
			return "CPU内存使用率:"+alarmDetails.cpuUsageRate+
			"% , CPU使用率告警门限:"+alarmDetails.cpuUsageThreshold+"%";
		}else if(row.alarmType==8){
			return "内存使用率:"+alarmDetails.memoryUsageRate+
			"% , 内存使用率告警门限:"+alarmDetails.memoryUsageThreshold+"%";
		}else if(row.alarmType==9){
			return  "硬盘使用率:"+alarmDetails.harddiskUsageRate+
			"% , 硬盘使用率告警门限:"+alarmDetails.harddiskUsageThreshold+"%";
		}else if(row.alarmType==10){
			return  "";
		}else{
			return formatJsonObject(row.alarmDetails);
		}
	}

	function formatFrontProcessorId(val, row, index) {
		var alarmDetails = row.alarmDetails;
		return alarmDetails.frontProcessorId;
	}
	
	function formatIsHandle(value) {
		
		if(value==0){
			return "<font color=red>否</font>";
		}else {
			return "是";
		}
	}
	
<%--/* 	onLoadSuccess:function(){--%>
	    <%--$(".datagrid-row").mouseover(function(){--%>
	    	<%--content: $('<div></div>'),--%>
	    	            <%--onShow: function(){--%>
	    	                <%--$(this).tooltip('arrow').css('left', 20);--%>
	    	                <%--$(this).tooltip('tip').css('left', $(this).offset().left);--%>
	    	            <%--},--%>
	    	            <%--onUpdate: function(cc){--%>
	    	                <%--cc.panel({--%>
	    	                    <%--width: 500,--%>
	    	                    <%--height: 'auto',--%>
	    	                    <%--border: false,--%>
	    	                    <%--href: '${pageContext.request.contextPath}/alarmInfo/exportByTemplate.do?alarmInfoIds='+null+''--%>
	    	                <%--});--%>
	    	            <%--}--%>
	    <%--});--%>
	<%--}  */--%>
	
	function formatAlarmTime(val, row, index) {
		var alarmDetails = row.alarmDetails;
		
		if(alarmDetails.timestamp===undefined){
			return formatDatebox(val);
		}else{
			//if(row.alarmType == 10){
				//return formatDatebox(alarmDetails.timestamp);
			//}
			return formatDatebox(val);
		}
	}
	
	function formatEndTime(val, row, index) {
		var alarmDetails = row.endTime;
		return row.endTime ? formatDatebox(val) : '';
		
	}
	
	formatterDate = function (date) {
		var day = date.getDate();
		var month = (date.getMonth() + 1);
		var hor = date.getHours();
		var min = date.getMinutes();
		var sec = date.getSeconds();
		return date.getFullYear() + '-' + month + '-' + day+" "+hor+":"+min+":"+sec;
	};

	$(function(){
		$('#i1').datetimebox('setValue', formatterDate(new Date(new Date(new Date().toLocaleDateString()).getTime())));
		$('#i2').datetimebox('setValue', formatterDate(new Date()));
		
		$('#dg').datagrid({
			//url:'',
			rowStyler:function(index,row){
				var alarmType = row.alarmType;
				
				if (alarmType == 4 || alarmType == 5 || alarmType == 6 || alarmType == 10 || alarmType == 11) {
					return 'background-color:pink;';
				}
			}
		});
	});
	
	
</script>
</head>
<body style="margin: 1px">
<table id="dg" title="GPRS数据中断统计" class="easyui-datagrid"
   fitColumns="fasle" pagination="true" rownumbers="true" pageSize="100" pageList="[100,200,300,400,500]"
   url="" fit="true" toolbar="#tb">
   <thead>
   	<tr>
   		<th field="cb" checkbox="true" align="center"></th>
   		<!-- <th field="alarmInfoId" width="100" align="center">告警信息ID</th>
   		<th field="alarmType1" width="100" align="center" formatter="formatAlarmClass">告警级别</th> -->
   		<!-- <th field="alarmObjectType" width="120" align="center">告警对象类型</th> -->
   		<!-- <th field="alarmObjectInfo" width="150" align="center">告警对象标识</th> -->
   		<!-- <th field="frontProcessorId" width="150" align="center" formatter="formatFrontProcessorId">前置机号</th>
   		<th field="siteName" width="150" align="center" >小区</th> -->
   		<th field="alarmType" width="200" align="center" formatter="formatAlarmType2">类型</th>
   		<th field="alarmNumber" width="200" align="center" >中断次数</th>
   		<th field="alarmTime" width="170" align="center" formatter="formatDatebox">最近中断产生时间</th>
   		<th field="endTime" width="170" align="center" formatter="formatEndTime">中断解除时间</th>
   		<th field="isHandle" width="80" align="center" formatter="formatIsHandle">是否已处理</th>
   		<th field="isNormal" width="100" align="center" formatter="formatIsNormal">解除方式</th>
   		<!-- <th field="alarmDetails" width="400" align="center" formatter="formatAlarmDetails">告警描述详情</th> -->
   	</tr>
   </thead>
 </table>
 <div id="tb">
 	<!-- <div>
 		<a href="javascript:exportAlarmInfoInCurrentPage()" class="easyui-linkbutton" iconCls="icon-save" plain="true">导出当前告警信息</a>
 		<a href="javascript:exportAlarmInfoInAllPages()" class="easyui-linkbutton" iconCls="icon-save" plain="true">导出所有告警信息</a>
 		<a href="javascript:exportByTemplateInCurrentPage()" class="easyui-linkbutton" iconCls="icon-save" plain="true">用模版导出当前告警信息</a>
 		<a href="javascript:exportByTemplateInAllPages()" class="easyui-linkbutton" iconCls="icon-save" plain="true">用模版导出所有告警信息</a>
 	</div> -->
 	<div style="margin-top:10px">
 		&nbsp;小区：&nbsp;
 		<input class="easyui-combobox" id="siteName" name="siteName" data-options="panelHeight:'auto',valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/alarmInfo/frontBaseName.do'" value="-1"/>   
 		<input type="text" id="i1" size="20" class="easyui-datetimebox"  style="width:150px" />
 		&nbsp;至&nbsp;
		<input type="text" id="i2" size="20" class="easyui-datetimebox"  style="width:150px" />
		
 		<a href="javascript:searchAlarmInfo()" class="easyui-linkbutton" iconCls="icon-search" plain="true"><b style="font-size:15px">搜索</b></a>
 	</div>
 </div>
 
</body>
</html>